﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Visitor_装饰_模式
{
    public interface IMedia
    {
    }
    #region Audio对象
    public abstract class AudioMedia : IMedia
    {
        public abstract void Accept(AudioVisitor visitor);
    }

    public class MP3 : AudioMedia
    {
        public override void Accept(AudioVisitor visitor)
        {
            visitor.VisitMP3();
        }
    }

    public class WAV : AudioMedia
    {
        public override void Accept(AudioVisitor visitor)
        {
            visitor.VisitWAV();
        }
    }
    #endregion

    #region Audio行为
    public abstract class AudioVisitor
    {
        public abstract void VisitMP3();
        public abstract void VisitWAV();
    }

    public class PlayAudioVisitor : AudioVisitor
    {

        public override void VisitMP3()
        {
            Console.WriteLine("播放mp3");
        }

        public override void VisitWAV()
        {
            Console.WriteLine("播放wav");
        }
    }

    public class ShowScriptAudioVisitor : AudioVisitor
    {
        public override void VisitMP3()
        {
            Console.WriteLine("显示内容mp3");
        }

        public override void VisitWAV()
        {
            Console.WriteLine("显示内容wav");
        }
    }

    #endregion

    #region Video对象
    public abstract class VideoMedia
    {
        public abstract void Accept(VideoVisitor visitor);
    }
    public class MP4 : VideoMedia
    {
        public override void Accept(VideoVisitor visitor)
        {
            visitor.VisitMP4();
        }
    }
    public class RMVB : VideoMedia
    {
        public override void Accept(VideoVisitor visitor)
        {
            visitor.VisitRMVB();
        }
    }

    #endregion

    #region Video行为
    public abstract class VideoVisitor
    {
        public abstract void VisitMP4();
        public abstract void VisitRMVB();
    }
    public class PlayVideoVisitor : VideoVisitor
    {
        public override void VisitMP4()
        {
            Console.WriteLine("播放mp4");
        }

        public override void VisitRMVB()
        {
            Console.WriteLine("播放RMVB");
        }
    }
    public class ResizeVideoVisitor : VideoVisitor
    {
        public override void VisitMP4()
        {
            Console.WriteLine("缩放mp4");
        }

        public override void VisitRMVB()
        {
            Console.WriteLine("缩放RMVB");
        }
    }

    #endregion

    class Person
    {
        public string Name { get; set; }
        public override string ToString()
        {
            return string.Format("用户名：{0}", Name);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            AudioMedia audioMedia = new MP3();
            audioMedia.Accept(new PlayAudioVisitor());
            audioMedia.Accept(new ShowScriptAudioVisitor());

            VideoMedia videoMedia = new RMVB();
            videoMedia.Accept(new PlayVideoVisitor());

            Person p = new Person { Name = "zzl" };
            Console.WriteLine(p.ToString());
        }
    }
}
